import { config } from "../config/config.js";
import { Http } from "../utils/http.js";

class Theme {
  /**
   *  获取主题集合
   * 类可以保存数据  类的对象可以保存状态
   */

  static locationA = "t-1";
  static locationE = "t-2";
  static locationF = "t-3";
  static locationH = "t-4";

  theme = []; // 类的对象

  async getTheme() {
    // 将获取的主题集合暂存 ,  通过返回数据的标识和页面数据对应
    const names = `${Theme.locationA},${Theme.locationE},${Theme.locationF},${Theme.locationH}`;
    this.theme = await Http.request({
      url: "theme/by/names",
      data: { names }
    });
  }

  getThemeA() {
    return this.theme.find(item => item.name === Theme.locationA);
  }

  getThemeE() {
    return this.theme.find(item => item.name === Theme.locationE);
  }

  getThemeF() {
    return this.theme.find(item => item.name === Theme.locationF);
  }

  getThemeH() {
    return this.theme.find(item => item.name === Theme.locationH);
  }

  static getHomeLocationEspu() {
    return Theme.getThemeSpuByName(Theme.locationE);
  }

  static getThemeSpuByName(name) {
    return Http.request({
      url: `theme/name/${name}/with_spu`
    });
  }
}

export { Theme };
